﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static T13DelegateAndEvent.DelegateBuy;

namespace T13DelegateAndEvent
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 委托
            //委托可以为空
            Buy buy = null;
            //定义对象
            DelegateBuy d = new DelegateBuy();
            //buy委托对象上有两个功能
            buy = new Buy(d.BuyApple);
            buy += new Buy(d.BuyOrange);
            //调用一次委托，可执行加载的2个功能
            Console.WriteLine(buy("张三"));
            //委托对象作为函数参数
            d.WhoBuy("李四", buy);
            buy -= d.BuyApple;
            d.WhoBuy("王五", buy);
            //取消委托
            buy = null;

            #endregion

            #region 事件
            EventBuy e = new EventBuy();
            Mrwang wang = new Mrwang();
            Mrzhang zhang = new Mrzhang();

            wang.Register(e);
            zhang.Register(e);

            e.Issue();
            #endregion

            #region 事件订阅
            Console.Write("请输入您的取款金额：");
            string amount = Console.ReadLine();
            Console.WriteLine("交易成功，请取出银行卡");
            //事件参数
            UserEventArgs user = new UserEventArgs("ZZ@126.com", "2391893213", amount);
            SubscribeSystem sub = new SubscribeSystem(new Bank(), user);
            #endregion


            Console.ReadKey();

        }
    }
}

